package io.renren.modules.generator.service.impl;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.generator.dao.ScoreDao;
import io.renren.modules.generator.entity.ScoreEntity;
import io.renren.modules.generator.service.ScoreService;


@Service("scoreService")
public class ScoreServiceImpl extends ServiceImpl<ScoreDao, ScoreEntity> implements ScoreService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<ScoreEntity> wrapper = new QueryWrapper<>();
        if (MapUtils.isNotEmpty(params)) {
            /**
             * 获取参数
             */
            Integer expertId = MapUtils.getInteger(params, "expertId");
            String key = MapUtils.getString(params, "key");

            if (expertId != null) {
                wrapper.eq("expert_id", expertId);
            }

            if (StringUtils.isNotBlank(key)) {
                wrapper.like("project_name", key);
            }

        }
        IPage<ScoreEntity> page = this.page(
                new Query<ScoreEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public List<ScoreEntity> queryByProjectId(Integer projectId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("project_id", projectId);
        List scoreList = this.baseMapper.selectList(wrapper);
        return scoreList;
    }

    @Override
    public List<ScoreEntity> queryByExpertId(Integer expertId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("expert_id", expertId);
        List scoreList = this.baseMapper.selectList(wrapper);
        return scoreList;
    }

}